#include <QApplication>
#include <QPushButton>
#include <QStateMachine>
#include <QSignalTransition>
#include <QPropertyAnimation>
#include <QParallelAnimationGroup>
#include <QSequentialAnimationGroup>

int main(int argc, char *argv[])
{
    QApplication a(argc, argv);
    //动画属性
//    QPushButton button("Animated Button");
//    button.show();
//    QPropertyAnimation animation(&button, "geometry");
//    animation.setDuration(10000);
//    animation.setKeyValueAt(0, QRect(0, 0, 100, 30));
//    animation.setKeyValueAt(0.8, QRect(250, 250, 100, 30));
//    animation.setKeyValueAt(1, QRect(0, 0, 100, 30));
//    animation.start();
    //缓和曲线
//    QPushButton button("Animated Button");
//    button.show();
//    QPropertyAnimation animation(&button, "geometry");
//    animation.setDuration(3000);
//    animation.setStartValue(QRect(0, 0, 100, 30));
//    animation.setEndValue(QRect(250, 250, 100, 30));
//    animation.setEasingCurve(QEasingCurve::OutBounce);
//    animation.start();
    //动画分组QAnimationGroup，QSequentialAnimationGroup，QParallelAnimationGroup
//    QPushButton *bonnie = new QPushButton("Bonnie");
//    bonnie->show();
//    QPushButton *clyde = new QPushButton("Clyde");
//    clyde->show();
//    // 动画一
//    QPropertyAnimation *anim1 = new QPropertyAnimation(bonnie, "geometry");
//    // 动画二
//    QPropertyAnimation *anim2 = new QPropertyAnimation(clyde, "geometry");
//    QParallelAnimationGroup *group = new QParallelAnimationGroup;
//    group->addAnimation(anim1);
//    group->addAnimation(anim2);
//    group->start();
//    QPushButton button("Animated Button");
//    button.show();
//    QPropertyAnimation anim1(&button, "geometry");
//    anim1.setDuration(3000);
//    anim1.setStartValue(QRect(0, 0, 100, 30));
//    anim1.setEndValue(QRect(500, 500, 100, 30));
//    QPropertyAnimation anim2(&button, "geometry");
//    anim2.setDuration(3000);
//    anim2.setStartValue(QRect(500, 500, 100, 30));
//    anim2.setEndValue(QRect(1000, 500, 100, 30));
//    QSequentialAnimationGroup group;
//    group.addAnimation(&anim1);
//    group.addAnimation(&anim2);
//    group.start();
    //动画和状态
    QPushButton *button = new QPushButton("Animated Button");
    button->show();
    QStateMachine *machine = new QStateMachine;
    QState *state1 = new QState(machine);
    state1->assignProperty(button, "geometry", QRect(0, 0, 100, 30));
    machine->setInitialState(state1);
    QState *state2 = new QState(machine);
    state2->assignProperty(button, "geometry", QRect(250, 250, 100, 30));
    QSignalTransition *transition1 = state1->addTransition(button,
        SIGNAL(clicked()), state2);
    transition1->addAnimation(new QPropertyAnimation(button, "geometry"));
    QSignalTransition *transition2 = state2->addTransition(button,
        SIGNAL(clicked()), state1);
    transition2->addAnimation(new QPropertyAnimation(button, "geometry"));
    machine->start();
    return a.exec();
}
